home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
365_03
/
vi.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-04
|
21KB
|
597 lines
/* vi.h */
/* Author:
* Steve Kirkendall
* 14407 SW Teal Blvd. #C
* Beaverton, OR 97005
* kirkenda@cs.pdx.edu
*/
#define VERSION "ELVIS 1.5, by Steve Kirkendall (23 March 1992)"
#define COPYING "This version of ELVIS is freely redistributable."
#include <errno.h>
extern int errno;
#if TOS && !defined(__GNUC__)
#define ENOENT (-AEFILNF)
#endif
#if TOS || VMS
# include <types.h>
# define O_RDONLY 0
# define O_WRONLY 1
# define O_RDWR 2
# ifdef __GNUC__
# define S_IJDIR S_IFDIR
# endif
#else
# if OSK
# include <modes.h>
# define O_RDONLY S_IREAD
# define O_WRONLY S_IWRITE
# define O_RDWR (S_IREAD | S_IWRITE)
# define ENOENT E_PNNF
# define sprintf Sprintf
# else
# include <sys/types.h>
# if COHERENT
# include <sys/fcntl.h>
# else
# include <fcntl.h>
# endif
# endif
#endif
#ifndef O_BINARY
# define O_BINARY 0
#endif
#include "curses.h"
#include <signal.h>
/*------------------------------------------------------------------------*/
/* Miscellaneous constants. */
#define INFINITY 2000000001L /* a very large integer */
#define LONGKEY 10 /* longest possible raw :map key */
#ifndef MAXRCLEN
# define MAXRCLEN 1000 /* longest possible :@ command */
#endif
/*------------------------------------------------------------------------*/
/* These describe how temporary files are divided into blocks */
#define MAXBLKS (BLKSIZE / sizeof(unsigned short))
typedef union
{
char c[BLKSIZE]; /* for text blocks */
unsigned short n[MAXBLKS]; /* for the header block */
}
BLK;
/*------------------------------------------------------------------------*/
/* These are used manipulate BLK buffers. */
extern BLK hdr; /* buffer for the header block */
extern BLK *blkget(); /* given index into hdr.c[], reads block */
extern BLK *blkadd(); /* inserts a new block into hdr.c[] */
/*------------------------------------------------------------------------*/
/* These are used to keep track of various flags */
extern struct _viflags
{
short file; /* file flags */
}
viflags;
/* file flags */
#define NEWFILE 0x0001 /* the file was just created */
#define READONLY 0x0002 /* the file is read-only */
#define HADNUL 0x0004 /* the file contained NUL characters */
#define MODIFIED 0x0008 /* the file has been modified, but not saved */
#define NOFILE 0x0010 /* no name is known for the current text */
#define ADDEDNL 0x0020 /* newlines were added to the file */
#define HADBS 0x0040 /* backspace chars were lost from the file */
#define UNDOABLE 0x0080 /* file has been modified */
#define NOTEDITED 0x0100 /* the :file command has been used */
/* macros used to set/clear/test flags */
#define setflag(x,y) viflags.x |= y
#define clrflag(x,y) viflags.x &= ~y
#define tstflag(x,y) (viflags.x & y)
#define initflags() viflags.file = 0;
/* The options */
extern char o_autoindent[1];
extern char o_autoprint[1];
extern char o_autotab[1];
extern char o_autowrite[1];
extern char o_columns[3];
extern char o_directory[30];
extern char o_edcompatible[1];
extern char o_equalprg[80];
extern char o_errorbells[1];
extern char o_exrefresh[1];
extern char o_ignorecase[1];
extern char o_keytime[3];
extern char o_keywordprg[80];
extern char o_lines[3];
extern char o_list[1];
extern char o_number[1];
extern char o_readonly[1];
extern char o_remap[1];
extern char o_report[3];
extern char o_scroll[3];
extern char o_shell[60];
extern char o_shiftwidth[3];
extern char o_sidescroll[3];
extern char o_sync[1];
extern char o_tabstop[3];
extern char o_term[30];
extern char o_flash[1];
extern char o_warn[1];
extern char o_wrapscan[1];
#ifndef CRUNCH
extern char o_beautify[1];
extern char o_exrc[1];
extern char o_mesg[1];
extern char o_more[1];
extern char o_novice[1];
extern char o_prompt[1];
extern char o_taglength[3];
extern char o_terse[1];
extern char o_window[3];
extern char o_wrapmargin[3];
extern char o_writeany[1];
#endif
#ifndef NO_ERRLIST
extern char o_cc[30];
extern char o_make[30];
#endif
#ifndef NO_CHARATTR
extern char o_charattr[1];
#endif
#ifndef NO_DIGRAPH
extern char o_digraph[1];
extern char o_flipcase[80];
#endif
#ifndef NO_SENTENCE
extern char o_hideformat[1];
#endif
#ifndef NO_EXTENSIONS
extern char o_inputmode[1];
extern char o_ruler[1];
#endif
#ifndef NO_MAGIC
extern char o_magic[1];
#endif
#ifndef NO_MODELINES
extern char o_modelines[1];
#endif
#ifndef NO_SENTENCE
extern char o_paragraphs[30];
extern char o_sections[30];
#endif
#if MSDOS
extern char o_pcbios[1];
#endif
#ifndef NO_SHOWMATCH
extern char o_showmatch[1];
#endif
#ifndef NO_SHOWMODE
extern char o_smd[1];
#endif
/*------------------------------------------------------------------------*/
/* These help support the single-line multi-change "undo" -- shift-U */
extern char U_text[BLKSIZE];
extern long U_line;
/*------------------------------------------------------------------------*/
/* These are used to refer to places in the text */
typedef long MARK;
#define markline(x) (long)((x) / BLKSIZE)
#define markidx(x) (int)((x) & (BLKSIZE - 1))
#define MARK_UNSET ((MARK)0)
#define MARK_FIRST ((MARK)BLKSIZE)
#define MARK_LAST ((MARK)(nlines * BLKSIZE))
#define MARK_AT_LINE(x) ((MARK)(x) * BLKSIZE)
#define NMARKS 29
extern MARK mark[NMARKS]; /* marks a-z, plus mark ' and two temps */
extern MARK cursor; /* mark where line is */
/*------------------------------------------------------------------------*/
/* These are used to keep track of the current & previous files. */
extern long origtime; /* modification date&time of the current file */
extern char origname[256]; /* name of the current file */
extern char prevorig[256]; /* name of the preceding file */
extern long prevline; /* line number from preceding file */
/*------------------------------------------------------------------------*/
/* misc housekeeping variables & functions */
extern int tmpfd; /* fd used to access the tmp file */
extern int tmpnum; /* counter used to generate unique filenames */
extern long lnum[MAXBLKS]; /* last line# of each block */
extern long nlines; /* number of lines in the file */
extern char args[BLKSIZE]; /* file names given on the command line */
extern int argno; /* the current element of args[] */
extern int nargs; /* number of filenames in args */
extern long changes; /* counts changes, to prohibit short-cuts */
extern int significant; /* boolean: was a *REAL* change made? */
extern BLK tmpblk; /* a block used to accumulate changes */
extern long topline; /* file line number of top line */
extern int leftcol; /* column number of left col */
#define botline (topline + LINES - 2)
#define rightcol (leftcol + COLS - (*o_number ? 9 : 1))
extern int physcol; /* physical column number that cursor is on */
extern int physrow; /* physical row number that cursor is on */
extern int exwrote; /* used to detect verbose ex commands */
extern int doingdot; /* boolean: are we doing the "." command? */
extern int doingglobal; /* boolean: are doing a ":g" command? */
extern long rptlines; /* number of lines affected by a command */
extern char *rptlabel; /* description of how lines were affected */
extern char *fetchline(); /* read a given line from tmp file */
extern char *parseptrn(); /* isolate a regexp in a line */
extern MARK paste(); /* paste from cut buffer to a given point */
extern char *wildcard(); /* expand wildcards in filenames */
extern MARK input(); /* inserts characters from keyboard */
extern char *linespec(); /* finds the end of a /regexp/ string */
#define ctrl(ch) ((ch)&037)
#ifndef NO_RECYCLE
extern long allocate(); /* allocate a free block of the tmp file */
#endif
extern int trapint(); /* trap handler for SIGINT */
extern int deathtrap(); /* trap handler for deadly signals */
extern void blkdirty(); /* marks a block as being "dirty" */
extern void blkflush(); /* writes a single dirty block to the disk */
extern void blks